<!DOCTYPE html>
<html class="ui-page-login">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<!-- build:css /css/main.css -->
		<link href="/css/mui.css" rel="stylesheet" />
		<link href="/css/iconfont.css" rel="stylesheet" />
		<link href="/css/common.css" rel="stylesheet" />
		<!-- endbuild -->
		<!-- build:css /css/login-min.css -->
		<link href="/css/login.css" rel="stylesheet" />
		<!-- endbuild -->

	</head>

	<body>
		<header class="mui-bar mui-bar-nav u-nav">
			<a id="back" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">登录</h1>
		</header>
		<div class="mui-content">
			<form id='login-form' class="mui-input-group">
				<div class="mui-input-row">
					<label><span class="mui-icon mui-icon-contact"></span></label>
					<input id='account' type="text" class="mui-input-clear mui-input" placeholder="请输入账号">
				</div>
				<div class="mui-input-row">
					<label><span class="mui-icon mui-icon-locked"></span></label>
					<input id='password' type="password" class="mui-input-clear mui-input" placeholder="请输入密码">
				</div>
				<div class="mui-input-row" id="err">

				</div>
			</form>
			<div class="mui-content-padded">
				<button id='login' class="mui-btn mui-btn-block mui-btn-danger">登录</button>
				<div class="link-area">
					<a id='reg'>注册账号</a> <span class="spliter">|</span>
					<a id='forgetPassword'>忘记密码</a>
				</div>
			</div>

		</div>
		<!-- build:js /js/vendor.js -->
		<script src="/js/mui.min.js"></script>
		<!-- bower:js -->
		<script src="/bower_components/mockjs/dist/mock.js"></script>
		<script src="/bower_components/zepto/zepto.js"></script>
		<script src="/bower_components/Zepto-Cookie/zepto.cookie.js"></script>
		<!--  endbower -->
		<!-- endbuild -->
		<!-- build:js /js/main.js -->
		<script src="/js/common.js"></script>
		<script src="/js/app.js"></script>
		<!-- endbuild -->

		<script>
			(function(mui, doc) {
				mui.ready(function() {
					var expiresDate = new Date();
					expiresDate.setTime(expiresDate.getTime() + (120 * 60 * 1000));
					var loginButton = $('#login');
					var accountBox = $('#account');
					var passwordBox = $('#password');
					var regButton = $('#reg');
					var forgetButton = $('#forgetPassword');
					loginButton.on('tap', function(event) {
						var loginInfo = {
							account: accountBox.val(),
							password: passwordBox.val()
						};
						var loginAcount = {
							account: accountBox.val(),
						}

						if(loginInfo.account == '' || loginInfo.password == '') {
							$("#err").html('请输入用户名或密码！')
							return false;
						} else {
							$.ajax({
									url: __BATE__ + 'api/login ',
									data: {
										account: loginInfo.account,
										password: loginInfo.password,
										code: codeVal
									},
									type: 'post',
									success: function(json, status, xhr) {
										if(json.ret_msg == '登录成功') {

											localStorage.setItem('$users', JSON.stringify(loginAcount));

											$.fn.cookie('token', json.token, {
												expires: expiresDate,
												path: '/'
											});
											toMain();

											$("#err").html('');
										} else {
											$("#err").html(json.ret_msg);
										}

									},
									error: function() {
										serverErr();
									}
								}

							);

						}

					});

					regButton.on('tap', function(event) {
						mui.openWindow({
							url: 'reg.html',
							id: 'reg',
							preload: true,
							show: {
								aniShow: 'pop-in'
							},
							styles: {
								popGesture: 'hide'
							},
							waiting: {
								autoShow: false
							}
						});
					}, false);
					forgetButton.on('tap', function(event) {
						mui.openWindow({
							url: 'forget-password.html',
							id: 'forget-password',
							preload: true,
							show: {
								aniShow: 'pop-in'
							},
							styles: {
								popGesture: 'hide'
							},
							waiting: {
								autoShow: false
							}
						});
					}, false);

				});
			}(mui, document));
		</script>
	</body>

</html>